from AudioFx import AudioSlot
from pyo import *

class Filter(AudioSlot):
    
    """
    example audio process
    """
    name = "LowPass filter"
    ctrls = ["freq","Q","gain"]
    def __init__(self):
        AudioSlot.__init__(self, "fx",self.name,self.ctrls)
        self.output = Biquad(
                    input=self.input, 
                    freq=(self.ctrl1**2)*10000+20, 
                    q=self.ctrl2*100+1, 
                    mul = self.ctrl3**2)
        self.addOff(self.output)
        self.initVals = [1,0,1]

class Verby(AudioSlot):
    
    """
    example audio process
    """
    name = "FreeVerb"
    ctrls = ["size","damp","bal"]
    def __init__(self):
        AudioSlot.__init__(self, "fx",self.name,self.ctrls)
        self.output = Freeverb(
                    input=self.input, 
                    size=self.ctrl1,
                    damp=self.ctrl2,
                    bal =self.ctrl3)
        self.addOff(self.output)
        self.initVals = [0.5,0.5,0.1]


class AllPassFilter(AudioSlot):
    """
    example audio process
    """
    name = "AllPassFilter"
    ctrls = ["freq","BandW","gain"]
    def __init__(self):
        AudioSlot.__init__(self, "fx", self.name,self.ctrls)
        self.output = Allpass2(
                     input=self.input, 
                     freq=(self.ctrl1**2)*10000+20, 
                     bw=self.ctrl2*100+1, 
                     mul=self.ctrl3**2)
        self.addOff(self.output)
        self.initVals = [1,0,1]
        
class Harmoniz(AudioSlot):
    """
    example audio process
    """
    name = "Harmonizer"
    ctrls = ["transpo","feedback","gain"]
    def __init__(self):
        AudioSlot.__init__(self, "fx", self.name,self.ctrls)
        self.output = Harmonizer(   
                     input=self.input,
                     transpo=(self.ctrl1)*12,
                     feedback=self.ctrl2,
                     mul=self.ctrl3**2) 
        self.addOff(self.output)
        self.initVals = [1,0.1,0.5]

class Choruss(AudioSlot):
    """
    example audio process
    """
    name = "Chorus"
    ctrls = ["depth","feedback","bal"]
    def __init__(self):
        AudioSlot.__init__(self, "fx", self.name,self.ctrls)
        self.output = Chorus(   
                     input=self.input,
                     depth=self.ctrl1*5,
                     feedback=self.ctrl2,
                     bal=self.ctrl3) 
        self.addOff(self.output)
        self.initVals = [1,0.1,0.6]       

class Distor(AudioSlot):
    """
    example audio process
    """
    name = "Distortion"
    ctrls = ["drive","slope","mul"]
    def __init__(self):
        AudioSlot.__init__(self, "fx", self.name,self.ctrls)
        self.output = Disto(   
                     input=self.input,
                     drive=self.ctrl1,
                     slope=(self.ctrl2**2),
                     mul=self.ctrl3**2) 
        self.addOff(self.output)
        self.initVals = [0.3,0.7,0.5]
        

        
class AllpassWavG(AudioSlot):
    """
    example audio process
    """
    name = "AllpassWaveGuide"
    ctrls = ["freq","feed","detune"]
    def __init__(self):
        AudioSlot.__init__(self, "fx", self.name,self.ctrls)
        self.output = AllpassWG(   
                     input=self.input,
                     freq=(self.ctrl1**2)*1000+20,
                     feed=self.ctrl2**2,
                     detune=self.ctrl3) 
        self.addOff(self.output)
        self.initVals = [0.1,0.5,0.5]

class WGVerby(AudioSlot):
    
    """
    example audio process
    """
    name = "WGReverb"
    ctrls = ["feedback","cutoff","bal"]
    def __init__(self):
        AudioSlot.__init__(self, "fx",self.name,self.ctrls)
        self.output = WGVerb(
                    input=self.input, 
                    feedback=self.ctrl1,
                    cutoff=(self.ctrl1**2)*10000+20,
                    bal=self.ctrl3)
        self.addOff(self.output)
        self.initVals = [0.5,0.4,0.4]  

class Echo(AudioSlot):
    
    """
    example audio process
    """
    name = "Delay"
    ctrls = ["delay","feedback","gain"]
    def __init__(self):
        AudioSlot.__init__(self, "fx",self.name,self.ctrls)
        self.output = Delay(
                    input=self.input, 
                    delay=self.ctrl1,
                    feedback=(self.ctrl1**2),
                    mul=self.ctrl3**2)
        self.addOff(self.output)
        self.initVals = [0.2,0.1,0.5]

class Decimator(AudioSlot):
    
    """
    example audio process
    """
    name = "Decimator"
    ctrls = ["bitdepth","srscale","gain"]
    def __init__(self):
        AudioSlot.__init__(self, "fx",self.name,self.ctrls)
        self.output = Degrade(
                    input=self.input, 
                    bitdepth=(self.ctrl1*32)+1,
                    srscale=((self.ctrl2**2)*0.999)+0.001,
                    mul=self.ctrl3**2)
        self.addOff(self.output)
        self.initVals = [0.5,1,0.5]


class Lfo(AudioSlot):
    """
    example audio process
    """
    name = "Lfo"
    ctrls = ["freq1","freq2","morph"]
    def __init__(self):
        AudioSlot.__init__(self, "mod",self.name,self.ctrls)
        self.modOut = Sine(self.ctrl1*5+0.01, mul = self.ctrl3*0.5,add = .5)+Sine(self.ctrl2*5+0.1, mul = (1-self.ctrl3)*.5,add=.5)
        self.initVals = [0,0,0.5]

# class EmptyFx(AudioSlot):
#     """
#     example audio process
#     """
#     name = "Empty"
#     ctrls = ["None","None","None"]
#     def __init__(self):
#         AudioSlot.__init__(self, "fx",self.name,self.ctrls)
#         self.output = self.input


# class EmptyMod(AudioSlot):
#     """
#     example audio process
#     """
#     name = "Empty"
#     ctrls = ["None","None","None"]
#     def __init__(self):
#         AudioSlot.__init__(self, "mod",self.name,self.ctrls)
        

# PUT MODULES IN HERE!
# Max 19 modules per category
name = "basicsFX"
slotType = "fx"
modulesDict = {0:{"class":Decimator},
                1:{"class":Filter},
                2:{"class":Verby},
                3:{"class":AllPassFilter},
                4:{"class":Harmoniz},
                5:{"class":Choruss},
                6:{"class":Distor},
                7:{"class":AllpassWavG},
                8:{"class":WGVerby},
                9:{"class":Echo}
                
                }

# for i in range(16):
#   modulesDict["fx"][i+3] = {"class":Filter} 
for i, slot in modulesDict.items():
    slot["name"] = slot["class"].name
    slot["ctrls"] = slot["class"].ctrls

# for slotypename, classesDict in modulesDict.items():#autogenerate dict acording to slot info 
#     for i, slot in classesDict.items():
#         slot["name"] = slot["class"].name
#         slot["ctrls"] = slot["class"].ctrls